<?php
/**
 * This file is part of the Agora distribution. 
 * Detailed copyright and licensing information can be found
 * in the gpl-3.0.txt file which should be included in the distribution.
 * 
 * @version		$Id: 3.0.14 Olympus 2010-09-28 rammstein4o $
 * @copyright  2007 - 2010 jVitals
 * @license   GPLv3 Open Source
 * @link       http://jvitals.com
 * @since      File available since initial release
 */
	defined('IN_AGORA') or die;

	class AgoraCommon
	{
		function getIP()
		{
			if (isset($_SERVER['REMOTE_ADDR']))
				return $_SERVER['REMOTE_ADDR'];
			else
				return '0.0.0.0';
		}

		function getRefferer()
		{
			if (isset($_SERVER['HTTP_REFERER']))
				return $_SERVER['HTTP_REFERER'];
			else
				return Agora::makeURL(array());
		}

		function getTotalPages($total_items, $per_page)
		{
			$pages = ceil($total_items / $per_page);
			if ($pages < 1) $pages = 1;
			return $pages;
		}

		function getPage($page_count)
		{
			static $page = 0;

			if ($page === 0) {
				$page = intval(Agora::getVar('p',1));

				if ($page < 1) {
					$page = 1;
				} elseif ($page > $page_count && $page_count > 0) {
					$page = $page_count;
				}
			}

			return $page;
		}
		
		function getUrlContent ($url) {
		
			if ((int)ini_get('allow_url_fopen')) {
				$result = file_get_contents($url);
			} elseif (function_exists('curl_init')) {
				$ch = curl_init();
				curl_setopt($ch, CURLOPT_URL, $url);
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
				$result = curl_exec($ch);
				curl_close($ch);
			} else {
				$result = false;
			}
			return $result;
			
		}
		
	}

?>